package com.fitness.fitness.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fitness.fitness.modal.course.entity.CourseComment;
import com.fitness.fitness.modal.course.params.CourseCommentQueryParams;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface CourseCommentMapper extends BaseMapper<CourseComment> {

    @Select("select * from t_course_comment c where c.course_id = #{queryParams.courseId} order by create_time desc")
    Page<CourseComment> getCourseCommentPage(Page<CourseComment> page, @Param("queryParams") CourseCommentQueryParams queryParams);

    @Select("<script>select * from t_course_comment c"
            + " <where>"
            + "<if test='queryParams.author != null and queryParams.author.trim() neq \"\"'>"
            + " AND c.author like  CONCAT('%',#{queryParams.author},'%')"
            + "</if>"
            + "<if test='queryParams.courseName != null and queryParams.courseName.trim() neq \"\"'>"
            + " AND c.courseName like  CONCAT('%',#{queryParams.courseName},'%')"
            + "</if>"
            + "</where>"
            +"</script>")
    Page<CourseComment> getAllCourseCommentPage(Page<CourseComment> page, @Param("queryParams") CourseCommentQueryParams queryParams);
}
